package com.example.module.shoppingCart.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.example.module.shoppingCart.form.CartUpdateForm;
import com.example.module.shoppingCart.form.GetShopingCartForm;
import com.example.module.shoppingCart.form.ShoppingCartAddForm;
import com.example.module.shoppingCart.form.ShoppingCartDeleteForm;
import com.example.module.shoppingCart.service.ShoppingCartService;
import com.example.module.shoppingCart.vo.GetShoppingCartVO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ghy
 * @date 2025/08/28
 * @description 购物车控制层
 */
@Validated
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;

    /*
     * 添加商品至购物车
     *
     * @param shoppingCartAddForm
     * @return void
     * */
    @PostMapping("/add")
    @SaCheckLogin
    public void addShoppingCart(@RequestBody ShoppingCartAddForm shoppingCartAddForm){
        shoppingCartService.addShoppingCart(shoppingCartAddForm);
    }

    /*
     *  根据商品Id查询对应收藏
     *
     * @param getShopingCartForm
     * @return getShoppingCartVO
     * */
    @PostMapping("/getShoppingCartByGoodsId")
    @SaCheckLogin
    public GetShoppingCartVO getShoppingCartByGoodsId(@RequestBody GetShopingCartForm getShopingCartForm){
        return shoppingCartService.getShoppingCartByGoodsId(getShopingCartForm);
    }

    /*
     * 从购物车中移除商品
     *
     * @param ShoppingCartDeleteForm
     * @return void
     * */
    @PostMapping("/delete")
    @SaCheckLogin
    public void deleteShoppingCart(@RequestBody ShoppingCartDeleteForm shoppingCartDeleteForm){
        shoppingCartService.deleteShoppingCart(shoppingCartDeleteForm);
    }

    /*
     * 批量修改购物车中的商品数量
     *
     * @param List<CartUpdateForm>
     * @return void
     * */
    @PostMapping("/update")
    @SaCheckLogin
    public void updateCart(@RequestBody List<CartUpdateForm> formList){
        shoppingCartService.updateCart(formList);
    }
}
